from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `zhan_swiper` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(255) NOT NULL  COMMENT '名称',
    `autoplay` BOOL NOT NULL  COMMENT '是否自动切换(默认true)' DEFAULT 1,
    `interval` VARCHAR(255) NOT NULL  COMMENT '滑块自动切换时间间隔（ms）' DEFAULT '3000',
    `loading` BOOL NOT NULL  COMMENT '是否加载中(默认false)' DEFAULT 0,
    `is_show` BOOL NOT NULL  COMMENT '是否显示（默认true' DEFAULT 1
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `zhan_user` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `email` VARCHAR(255)   COMMENT '邮箱',
    `username` VARCHAR(255) NOT NULL  COMMENT '用户名',
    `password` VARCHAR(255) NOT NULL  COMMENT '密码',
    `login_type` INT NOT NULL  COMMENT '登录类型' DEFAULT 1,
    `status` INT NOT NULL  COMMENT '用户状态' DEFAULT 1,
    `authority` INT NOT NULL  COMMENT '权限' DEFAULT 1,
    `user_phone` VARCHAR(255)   COMMENT '手机号'
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `chat_application` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `title` VARCHAR(255) NOT NULL  COMMENT '标题',
    `desc` LONGTEXT NOT NULL  COMMENT '描述',
    `icon` LONGTEXT NOT NULL  COMMENT '图标',
    `instruct` LONGTEXT NOT NULL  COMMENT '指令',
    `examples` LONGTEXT NOT NULL  COMMENT '示例模板',
    `application_type` INT NOT NULL  COMMENT '应用类型：公共1，个人2' DEFAULT 1,
    `user_id_id` INT,
    CONSTRAINT `fk_chat_app_zhan_use_667206ca` FOREIGN KEY (`user_id_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `chat_session` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `session_title` VARCHAR(255) NOT NULL  COMMENT '会话标题',
    `model` VARCHAR(255) NOT NULL  COMMENT '会话模型',
    `object` VARCHAR(255) NOT NULL,
    `user_id_id` INT NOT NULL,
    CONSTRAINT `fk_chat_ses_zhan_use_9b708f89` FOREIGN KEY (`user_id_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `chat_message` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `message` LONGTEXT NOT NULL  COMMENT '信息',
    `message_action` INT NOT NULL  COMMENT '消息类型：用户1，AI2' DEFAULT 1,
    `role` VARCHAR(255) NOT NULL  COMMENT '发送者',
    `owner_chat_id` INT NOT NULL,
    `owner_user_id` INT NOT NULL,
    CONSTRAINT `fk_chat_mes_chat_ses_10e6ea08` FOREIGN KEY (`owner_chat_id`) REFERENCES `chat_session` (`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_chat_mes_zhan_use_2cb1fb14` FOREIGN KEY (`owner_user_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `zhan_application` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `title` VARCHAR(255) NOT NULL  COMMENT '标题',
    `desc` VARCHAR(255) NOT NULL  COMMENT '描述',
    `hide` BOOL NOT NULL  COMMENT '是否隐藏（默认false）' DEFAULT 0,
    `image_url` LONGTEXT NOT NULL  COMMENT '背景图地址',
    `page_url` VARCHAR(255) NOT NULL  COMMENT '点击跳转页面(没有权限不可进入)',
    `application_group` INT NOT NULL  COMMENT '应用分组：轮播图分组，热门分组...' DEFAULT 0,
    `icon_url` LONGTEXT NOT NULL  COMMENT '图标地址',
    `created_by_id` INT NOT NULL,
    `update_by_id` INT NOT NULL,
    CONSTRAINT `fk_zhan_app_zhan_use_2c2e1e78` FOREIGN KEY (`created_by_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_zhan_app_zhan_use_93dd65bc` FOREIGN KEY (`update_by_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `zhan_member` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `status` INT NOT NULL  COMMENT '会员状态' DEFAULT 1,
    `opening_time` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `expiration_time` DATETIME(6) NOT NULL,
    `user_id` INT NOT NULL,
    CONSTRAINT `fk_zhan_mem_zhan_use_ffea8490` FOREIGN KEY (`user_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
